<template>
  <div class="setting-container">
    <h4 class="setting-title">{{ $t('布局配置') }}</h4>
    <SelectLayoutMode />
    <el-divider />
    <h4 class="setting-title">{{ $t('功能配置') }}</h4>
    <div v-for="(settingValue, settingName, index) in switchSettings" :key="index" class="setting-item">
      <span class="setting-name">{{ settingName }}</span>
      <el-switch v-model="settingValue.value" :disabled="!isLeft && settingName === $t('固定头部')" />
    </div>
    <el-button type="danger" :icon="Refresh" @click="resetConfigLayout">{{ $t('重置') }}</el-button>
  </div>
</template>

<script setup>
import { watchEffect } from 'vue'
import { storeToRefs } from 'pinia'
import { useSettingsStore } from '@/store'
import { useLayoutMode } from '@/hooks/useLayoutMode'
import { resetConfigLayout } from '@/utils'
import SelectLayoutMode from './SelectLayoutMode.vue'
import { Refresh } from '@element-plus/icons-vue'
import { $t } from '@/languages/index'
const { isLeft } = useLayoutMode()
const settingsStore = useSettingsStore()

/** 使用 storeToRefs 将提取的属性保持其响应性 */
const {
  showTagsView,
  showLogo,
  fixedHeader,
  showFooter,
  showNotify,
  showThemeSwitch,
  showScreenfull,
  showSearchMenu,
  cacheTagsView,
  showDownload,
  showWatermark,
  showGreyMode,
  showColorWeakness
} = storeToRefs(settingsStore)

/** 定义 switch 设置项 */
const switchSettings = computed(() => ({
  [$t('显示标签页')]: showTagsView,
  [$t('显示logo')]: showLogo,
  [$t('固定头部')]: fixedHeader,
  [$t('显示底部')]: showFooter,
  [$t('显示通知')]: showNotify,
  [$t('显示主题切换')]: showThemeSwitch,
  [$t('显示全屏')]: showScreenfull,
  [$t('显示搜索')]: showSearchMenu,
  [$t('缓存标签页')]: cacheTagsView,
  [$t('显示下载')]: showDownload,
  [$t('显示水印')]: showWatermark,
  [$t('显示灰色模式')]: showGreyMode,
  [$t('显示色弱模式')]: showColorWeakness
}))

/** 非左侧模式时，Header 都是 fixed 布局 */
watchEffect(() => {
  !isLeft.value && (fixedHeader.value = true)
})
</script>

<style lang="scss" scoped>
@use '@/styles/mixins.scss';

.setting-container {
  padding: 20px;
  .setting-title {
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: 600;
    color: #303133;
    position: relative;
    padding-left: 12px;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 4px;
      height: 16px;
      background-color: #409eff;
      border-radius: 2px;
    }
  }
  .setting-item {
    font-size: 14px;
    color: var(--el-text-color-regular);
    padding: 5px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .setting-name {
      @extend %ellipsis;
    }
  }
  .el-button {
    margin-top: 40px;
    width: 100%;
  }
}
</style>
